<?php
namespace common\modules\favorite\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use common\modules\user\models\User;
use common\modules\favorite\models\query\FavoriteQuery;

/**
 * This is the model class for table "{{%favorite}}".
 *
 * @property integer $id
 * @property integer $user_id
 * @property integer $object_type
 * @property integer $object_id
 * @property integer $created_at
 *
 * @property User $user
 */
class Comment extends \yii\db\ActiveRecord
{

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%favorite}}';
    }

    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return [
            [
                'class' => TimestampBehavior::className(),
                'updatedAtAttribute' => false
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [
                [
                    'user_id',
                    'object_type',
                    'object_id'
                ],
                'required'
            ],
            [
                [
                    'user_id',
                    'object_type',
                    'object_id'
                ],
                'integer'
            ]
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('common', 'ID'),
            'user_id' => Yii::t('common', 'User ID'),
            'object_type' => Yii::t('common', 'Object Type'),
            'object_id' => Yii::t('common', 'Object ID'),
            'created_at' => Yii::t('common', 'Created At')
        ];
    }

    /**
     *
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::className(), [
            'id' => 'user_id'
        ]);
    }

    /**
     * @inheritdoc
     *
     * @return \common\modules\favorite\models\query\FavoriteQuery the active query used by this AR class.
     */
    public static function find()
    {
        return new FavoriteQuery(get_called_class());
    }
}
